<?php
/**
 * Objects store a set of objects returned from the database
 *
 * @category   Epic
 * @package    Epic_Db
 * @author     Epic Core Team <rukanhitokiri@gmail.com>
 */
abstract class Epic_Db_Collection_Abstract implements Iterator, Countable
{
	/**
     * Number entity to collection
     * @var int
     */
	private $_total = 0;
	
	/**
	 * Array of entity objects
     * @var array
     */
    protected $_entities = array();
   
    /**
     * Add a entity to collection
     * 
     * @param array $data
     */
    public function add(Epic_Db_Model_Object $row)
    {
    	$this->_entities[$this->_total] = $row;
		$this->_total++;
    } 
    
    /**
     * Reset the collection of entities (implementation required by Iterator Interface)
     */
    public function rewind()
    {
        reset($this->_entities);
    }
   
    /**
     * Get the current entity in the collection (implementation required by Iterator Interface)
     */ 
    public function current()
    {
        return current($this->_entities);
    }
   
    /**
     * Move to the next entity in the collection (implementation required by Iterator Interface)
     */
    public function next()
    {
        next($this->_entities);
    }
   
    /**
     * Get the key of the current entity in the collection (implementation required by Iterator Interface)
     */
    public function key()
    {
        return key($this->_entities);
    }
   
    /**
     * Check if there are more entities in the collection (implementation required by Iterator Interface)
     */
    public function valid()
    {
        return (boolean) $this->current();
    }
   
    /**
     * Count the number of entities in the collection (implementation required by Countable Interface)
     */
    public function count()
    {
        return count($this->_entities);
    }
}